/**
 * Subject.java is created by Zachariah at 2012-2-14 下午05:54:24
 */
package com.zack.designPattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zachariah zzcfrog@gmail.com
 *
 */
public class Subject implements ISubject {

	
	private List<IObserver> observers;
	
	public Subject(){
		this.observers = new ArrayList<IObserver>();
	}
	/**
	 * @see com.zack.designPattern.observer.ISubject#addObserver(com.zack.designPattern.observer.IObserver)
	 */
	@Override
	public void addObserver(IObserver o) {
		observers.add(o);

	}

	/**
	 * @see com.zack.designPattern.observer.ISubject#delObserver(com.zack.designPattern.observer.IObserver)
	 */
	@Override
	public void delObserver(IObserver o) {
		observers.remove(o);

	}

	/**
	 * @see com.zack.designPattern.observer.ISubject#notifyAllObservers()
	 */
	@Override
	public void notifyAllObservers() {
		for(IObserver o: observers){
			o.update();
		}

	}

}
